
package com.wyzz.hr.bo.impl;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.criterion.*;

import com.wyzz.hr.bo.IInmatchBasicBO;
import com.wyzz.hr.dao.IInmatchBasicDAO;
import com.wyzz.hr.pojo.Inmatch;
import com.wyzz.hr.pojo.InmatchBasic;
import com.wyzz.hr.pojo.Iodef;


public class InmatchBasicBOImpl implements IInmatchBasicBO {

	public InmatchBasicBOImpl() {
	}

	public IInmatchBasicDAO getDao() {
		return dao;
	}

	public void setDao(IInmatchBasicDAO dao) {
		this.dao = dao;
	}

	public InmatchBasic loadObject(String id) {
		return (InmatchBasic) dao.loadObject(
				com.wyzz.hr.pojo.InmatchBasic.class, id, null, new boolean[0]);
	}

	public boolean saveOrUpdateObject(InmatchBasic imb) {
		dao.saveOrupdate(imb);
		if (imb.getImList() != null)
			dao.saveOrupdate(imb.getImList());
		return true;
	}

	public boolean deleteObject(InmatchBasic imb) {
		if (imb.getImList() != null)
			dao.deleteCollection(imb.getImList());
		dao.deleteObject(imb);
		return true;
	}

	public List getListByIodef(Iodef iodef) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.InmatchBasic.class);
		detachedCriteria.add(Restrictions.eq(InmatchBasic.PROP_IMB_IO, iodef));
		detachedCriteria.addOrder(Order.asc(InmatchBasic.PROP_IMB_SORT_ID));
		List result = dao.findByCriteria(detachedCriteria);
		return result;
	}

	public List createInmatch(Iodef iodef) {
		List imbList = getListByIodef(iodef);
		List result = new ArrayList();
		for (int i = 0; i < imbList.size(); i++) {
			Inmatch imTmp = new Inmatch();
			InmatchBasic imbTmp = (InmatchBasic) imbList.get(i);
			imTmp.initByInmatchBasic(imbTmp);
			imTmp.setAllMaps();
			result.add(imTmp);
		}

		return result;
	}

	public void initInmatchBasicMaps(List imbList) {
		for (int i = 0; i < imbList.size(); i++)
			((InmatchBasic) imbList.get(i)).setAllMaps();

	}

	public boolean updateImbImList(List imbList, List imList) {
		if (imbList != null && imbList.size() > 0)
			dao.saveOrupdate(imbList);
		if (imList != null && imList.size() > 0)
			dao.saveOrupdate(imList);
		return true;
	}

	private IInmatchBasicDAO dao;
}
